/
TimePeriodsSort.php
68 lines (54 loc) 路 1.3 KB
/
TimePeriodsSort.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
declare(strict_types=1);
namespace Aeon\Calendar\Gregorian;
/**
* @psalm-immutable
*/
final class TimePeriodsSort
{
private const START_DATE_ASC = 1;
private const START_DATE_DESC = 2;
private const END_DATE_ASC = 3;
private const END_DATE_DESC = 4;
private int $type;
private function __construct(int $type)
{
$this->type = $type;
}
/**
* @psalm-pure
*/
public static function asc() : self
{
return self::startDate();
}
/**
* @psalm-pure
*/
public static function desc() : self
{
return self::startDate(false);
}
/**
* @psalm-pure
*/
public static function startDate(bool $ascending = true) : self
{
return new self($ascending ? self::START_DATE_ASC : self::START_DATE_DESC);
}
/**
* @psalm-pure
*/
public static function endDate(bool $ascending = true) : self
{
return new self($ascending ? self::END_DATE_ASC : self::END_DATE_DESC);
}
public function byStartDate() : bool
{
return $this->type === self::START_DATE_ASC || $this->type === self::START_DATE_DESC;
}
public function isAscending() : bool
{
return $this->type === self::START_DATE_ASC || $this->type === self::END_DATE_ASC;
}
}